//
//  MarketingOneCell.m
//  EMMApp
//
//  Created by Mac on 16/6/30.
//  Copyright © 2016年 YiXun. All rights reserved.
//

#import "MarketingOneCell.h"
#import "MarketingNewCollectionCell.h"
#import "BuildingStatusList.h"

@interface MarketingOneCell () {
    NSInteger num;
}
@property (nonatomic, strong) NSMutableArray *subDataArr;
@end

@implementation MarketingOneCell

- (void)awakeFromNib {
    [super awakeFromNib];
    _subDataArr = [[NSMutableArray alloc] init];

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)initWithMarketingOneCellArray:(NSMutableArray *)mArr {
    _subDataArr = mArr;
    [self creatCollectionView];
}

#pragma mark - UICollectionView初始化
- (void)creatCollectionView {
    UICollectionViewFlowLayout *layuet = [[UICollectionViewFlowLayout alloc] init];
    //垂直行间距
    layuet.minimumLineSpacing = 1;
    //水平间隔
    layuet.minimumInteritemSpacing = 1;
    
    [layuet setScrollDirection:UICollectionViewScrollDirectionVertical];

    float h = _subDataArr.count/2.00;

    self.homeCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 30*ceilf(h)) collectionViewLayout:layuet];
    [self.homeCollectionView registerNib:[UINib nibWithNibName:@"MarketingNewCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"MarketingNewCollectionCell"];
    self.homeCollectionView.delegate = self;
    self.homeCollectionView.dataSource = self;
    self.homeCollectionView.backgroundColor = [UIColor whiteColor];
    self.homeCollectionView.scrollEnabled = NO;
    [self addSubview:self.homeCollectionView];
}




#pragma mark - UICollectionViewDataSource / UICollectionViewDelegate /UICollectionViewDelegateFlowLayout 代理
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return _subDataArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellId = @"MarketingNewCollectionCell";
    MarketingNewCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];
    if (_subDataArr.count > 0) {
        BuildingStatusList *list = [_subDataArr objectAtIndex:indexPath.row];
        NSString *str = @"%";
        cell.markName.text = [NSString stringWithFormat:@"%@ %@%@",list.buildingStatus, list.buildingProportion,str];
        //：销控、未售、认筹、认购、签约、保留、暂不可售
        if ([list.buildingStatus isEqualToString:@"销控"]) {
            cell.markYSLabel.backgroundColor = [UIColor colorFromHexCode:@"#d3dbe7"];
        }else if ([list.buildingStatus isEqualToString:@"可售"]) {
            //        cell.markYSLabel.backgroundColor = [UIColor colorFromHexCode:@"#6ac96b"];
            cell.markYSLabel.backgroundColor = [UIColor whiteColor];
            cell.markYSLabel.layer.borderColor = [[UIColor colorFromHexCode:@"#CCCCCC"]CGColor];
            cell.markYSLabel.layer.borderWidth = 0.5f;
            cell.markYSLabel.layer.cornerRadius = 2.f;
            cell.markYSLabel.layer.masksToBounds = YES;
        }else if ([list.buildingStatus isEqualToString:@"认筹"]) {
            cell.markYSLabel.backgroundColor = [UIColor colorFromHexCode:@"#00ff00"];
        }else if ([list.buildingStatus isEqualToString:@"认购"]) {
            cell.markYSLabel.backgroundColor = [UIColor colorFromHexCode:@"#ff0000"];
        }else if ([list.buildingStatus isEqualToString:@"签约"]) {
            cell.markYSLabel.backgroundColor = [UIColor colorFromHexCode:@"#cd00ff"];
        }else if ([list.buildingStatus isEqualToString:@"保留"]) {
            cell.markYSLabel.backgroundColor = [UIColor colorFromHexCode:@"#66cdcc"];
        }else if ([list.buildingStatus isEqualToString:@"暂不可售"]) {
            cell.markYSLabel.backgroundColor = [UIColor colorFromHexCode:@"#818181"];
        }
    }
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake((EMM_WIDTH-20)/2, 30);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

@end
